﻿#Region "Copyright"
'————————————————————————————————————————
'       创建人员(Creator)    ：Huangyd
'       创建日期(Date)       ：2012-11-10
'   联系方式(Email)      ：aj-ayumi@163.com; gajayumi@gmail.com; ajayumi@me.com
'   描    述(Description)：
'
'       Copyright (C) 2012 ajayumi 版权所有
'————————————————————————————————————————
#End Region

Imports System.Net
Imports System.Text
Imports System.IO
Imports System.ComponentModel
Imports System.Text.RegularExpressions
Imports System.Runtime.CompilerServices
Imports System.IO.Compression

Namespace Net
    ''' <summary>
    ''' 处理网页相关业务的助理类
    ''' </summary>
    ''' <remarks></remarks>
    Public Class WebAssistant
        Implements IDisposable


#Region "Variables"
        Private m_CookieContainer As CookieContainer = Nothing
        'Private m_Delay As Integer = 3000
        'Private m_CurrentTry As Integer = 0     '当前重试次数
        'Private m_MaxTry As Integer = 3
        'Private m_BufferSize As Integer = 4096
        'Private m_Buffer(Me.m_BufferSize) As Byte
        'Private m_HtmlCode As String = String.Empty
        'Private m_isDone As Boolean = False
        'Private m_Title As String = String.Empty

        'Private m_Increment As Long = 0L        '增量,表示读取到的位置,最后可以表示文件的长度
        'Private m_ContentLength As Long = 0L
        'Private m_MemoryStream As MemoryStream = Nothing

        'Private m_WebRequest As WebRequest = Nothing
        'Private m_WebResponse As WebResponse = Nothing
#End Region

#Region "Properties"

        ''' <summary>
        ''' Cookie 容器，务必是应用程序的全局变量
        ''' </summary>
        Public Property [CookieContainer]() As CookieContainer

        ''' <summary>
        ''' 网站地址
        ''' </summary>
        Public ReadOnly Property SiteUrl() As String
            Get
                Return Me.SiteUri.OriginalString
            End Get
        End Property

        ''' <summary>
        ''' 站点地址
        ''' </summary>
        Public Property SiteUri As Uri = Nothing

        Public Property [Accept]() As String = String.Empty

        Public Property [UserAgent]() As String = String.Empty

        ''' <summary>
        ''' 网页提交的方式，Get 或 Post
        ''' </summary>
        Public Property [Method]() As MethodType = MethodType.Get

        ''' <summary>
        ''' 网页编码方式
        ''' </summary>
        Public Property [Encoding]() As Encoding = Encoding.Default

        Public Property ContentType() As String = "application/x-www-form-urlencoded"

        ''' <summary>
        ''' RefererHttp标头的值
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property [Referer] As String = String.Empty

        ''' <summary>
        ''' '提交数据的字符串
        ''' </summary>
        Public Property PostDataStr As String = String.Empty

        ' ''' <summary>
        ' ''' 代理服务器地址
        ' ''' </summary>
        'Public Property ProxyAddress() As String

        ' ''' <summary>
        ' ''' 网页标题 
        ' ''' </summary>
        'Public ReadOnly Property Title() As String
        '    Get
        '        Return Me.m_Title
        '    End Get
        'End Property

        ' ''' <summary>
        ' ''' 超时时间
        ' ''' </summary>
        'Public WriteOnly Property [Delay]() As Integer
        '    Set(ByVal value As Integer)
        '        m_Delay = value
        '    End Set
        'End Property

        ' ''' <summary>
        ' ''' 最大重试次数
        ' ''' </summary>
        'Public WriteOnly Property MaxTry() As Integer
        '    Set(ByVal value As Integer)
        '        m_MaxTry = value
        '    End Set
        'End Property

        ' ''' <summary>
        ' ''' 缓存大小
        ' ''' </summary>
        'Public WriteOnly Property BufferSize() As Integer
        '    Set(ByVal value As Integer)
        '        m_BufferSize = value
        '        Me.m_Buffer = New Byte(value) {}
        '    End Set
        'End Property

        ' ''' <summary>
        ' ''' 网页文件的长度
        ' ''' </summary>
        'Public ReadOnly Property getContentLength() As Long
        '    Get
        '        Return Me.m_ContentLength
        '    End Get
        'End Property


        ' ''' <summary>
        ' ''' 网页源码
        ' ''' </summary>
        'Public ReadOnly Property HtmlCode() As String
        '    Get
        '        Return m_HtmlCode
        '    End Get
        'End Property

        ' ''' <summary>
        ' ''' 网络数据量
        ' ''' </summary>
        'Public ReadOnly Property NetStream() As Stream
        '    Get
        '        Return Me.m_MemoryStream
        '    End Get
        'End Property

        ' ''' <summary>
        ' ''' 是否完成
        ' ''' </summary>
        'Public Property IsDone() As Boolean
        '    Get
        '        Return m_isDone
        '    End Get
        '    Set(ByVal value As Boolean)
        '        m_isDone = value
        '    End Set
        'End Property


#End Region

#Region "Constructors"

        'Public Sub New()
        '    Me.New(String.Empty)
        'End Sub

        Public Sub New(ByVal url As String)
            Me.New(New Uri(url), Nothing)
        End Sub

        Public Sub New(ByVal url As String, ByVal cc As CookieContainer)
            Me.New(New Uri(url), String.Empty, cc)
        End Sub

        Public Sub New(ByVal siteUri As Uri)
            Me.New(siteUri, Nothing)
        End Sub

        Public Sub New(ByVal siteUri As Uri, referer As String)
            Me.New(siteUri, referer, Nothing)
        End Sub

        Public Sub New(ByVal siteUri As Uri, referer As String, ByVal cc As CookieContainer)
            Me.SiteUri = siteUri
            Me.Referer = referer
            Me.m_CookieContainer = cc

            Me.InitDefaultValues()
            Console.WriteLine("访问 {0} 开始，{1} 实例化 WebAssistant 类.", Me.SiteUrl, DateTime.Now())

        End Sub

#End Region

#Region "Events"
        ''' <summary>
        ''' 访问网络过程中触发事件，e.State 为 HttpHelper 对象
        ''' </summary>
        ''' <remarks></remarks>
        Public Event [ProgressChanged] As ProgressChangedEventHandler
        ''' <summary>
        ''' 访问网络完成触发事件，e.State 为 HttpHelper 对象
        ''' </summary>
        ''' <remarks></remarks>
        Public Event [Completed] As AsyncCompletedEventHandler

        ''' <summary>
        ''' 访问网络过程中触发事件
        ''' </summary>
        ''' <param name="e">HttpHelper 对象</param>
        ''' <remarks></remarks>
        Public Overridable Sub OnProgressChanged(ByVal e As ProgressChangedEventArgs)
            If e IsNot Nothing Then RaiseEvent ProgressChanged(Me, e)
        End Sub

        ''' <summary>
        ''' 访问网络完成触发事件
        ''' </summary>
        ''' <param name="e">HttpHelper 对象</param>
        ''' <remarks></remarks>
        Public Overridable Sub OnCompleted(ByVal e As AsyncCompletedEventArgs)
            If e IsNot Nothing Then RaiseEvent Completed(Me, e)
        End Sub
#End Region

#Region "Methods"

        ''' <summary>
        ''' 初始化默认值
        ''' </summary>
        ''' <remarks></remarks>
        Private Sub InitDefaultValues()
            Dim _StringBuilder As New StringBuilder()
            _StringBuilder.Append("image/*, ")
            _StringBuilder.Append("application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, ")
            _StringBuilder.Append("application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, ")
            _StringBuilder.Append("application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*")
            Me.Accept = _StringBuilder.ToString()
            Me.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 7.0; MSIE 8.0; MSIE 9.0; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"
        End Sub

        ''' <summary>
        ''' 4.0以下.net版本取数据使用
        ''' </summary>
        ''' <param name="streamResponse">流</param>
        Private Function GetMemoryStream(streamResponse As Stream) As MemoryStream
            Dim _stream As New MemoryStream()
            Dim Length As Integer = 256
            Dim buffer As [Byte]() = New [Byte](Length - 1) {}
            Dim bytesRead As Integer = streamResponse.Read(buffer, 0, Length)
            ' write the required bytes  
            While bytesRead > 0
                _stream.Write(buffer, 0, bytesRead)
                bytesRead = streamResponse.Read(buffer, 0, Length)
            End While
            Return _stream
        End Function


        ''' <summary>
        ''' 设置WebRequest对象的属性
        ''' </summary>
        ''' <param name="req"></param>
        ''' <remarks></remarks>
        Private Sub SetWebRequestProperties(ByRef req As WebRequest)
            With req
                If TypeOf req Is HttpWebRequest Then
                    With DirectCast(req, HttpWebRequest)
                        .CookieContainer = Me.m_CookieContainer
                        .ContentType = Me.ContentType
                        .Referer = Me.Referer
                        .Accept = Me.Accept
                        .UserAgent = Me.UserAgent
                    End With
                ElseIf TypeOf req Is FileWebRequest Then
                    With DirectCast(req, FileWebRequest)
                        .ContentType = Me.ContentType
                    End With
                ElseIf TypeOf req Is FtpWebRequest Then
                    With DirectCast(req, FileWebRequest)
                        .ContentType = Me.ContentType
                    End With
                End If

                .Method = Me.Method.ToString()

                'If Not String.IsNullOrEmpty(Me.ProxyAddress) Then
                '.Proxy = New WebProxy("58.215.81.185", 1080)
                'End If
            End With

            If Not String.IsNullOrEmpty(Me.PostDataStr) Then
                Dim _data() As Byte = Me.Encoding.GetBytes(Me.PostDataStr)
                If _data.Length > 0 Then
                    req.ContentLength = _data.Length
                    Using _Stream As Stream = req.GetRequestStream()
                        _Stream.Write(_data, 0, _data.Length)
                    End Using
                End If
            End If

        End Sub

#Region "异步获取网页源码"
        '        Protected Overridable Sub RequestComplete(ByVal ar As IAsyncResult)
        '            Try
        '                Me.m_WebRequest = CType(ar.AsyncState, WebRequest)
        '                Me.m_WebResponse = CType(Me.m_WebRequest.EndGetResponse(ar), WebResponse)

        '                Me.m_WebResponse.GetResponseStream.BeginRead(Me.m_Buffer, CInt(Me.m_Increment), Me.m_BufferSize, New AsyncCallback(AddressOf ResponseComplete), Me.m_WebResponse)
        '            Catch ex As Exception
        '                Me.OnCompleted(New AsyncCompletedEventArgs(ex, True, Me))
        '            End Try
        '        End Sub

        '        Protected Overridable Sub ResponseComplete(ByVal ar As System.IAsyncResult)
        '            Try
        '                Me.m_WebResponse = CType(ar.AsyncState, WebResponse)
        '                Dim Bytes As Integer = Me.m_WebResponse.GetResponseStream().EndRead(ar)

        '                If (Bytes > 0) Then
        '                    Me.m_MemoryStream.Write(Me.m_Buffer, 0, Bytes)
        '                    Me.m_Increment += Bytes

        '                    Me.OnProgressChanged(New ProgressChangedEventArgs(CInt(Me.m_Increment), Me))
        '                    Me.m_WebResponse.GetResponseStream.BeginRead(Me.m_Buffer, 0, Me.m_BufferSize, New AsyncCallback(AddressOf ResponseComplete), Me.m_WebResponse)
        '                Else
        '                    Me.m_isDone = True  '访问网络完成

        '                    Me.ContentType = Me.m_WebResponse.ContentType
        '                    Me.m_ContentLength = Me.m_Increment


        '                    If TypeOf m_WebResponse Is HttpWebResponse Then

        '                        With DirectCast(m_WebResponse, HttpWebResponse)
        '                            'GZIIP处理
        '                            'If .ContentEncoding IsNot Nothing AndAlso .ContentEncoding.Equals("gzip", StringComparison.InvariantCultureIgnoreCase) Then
        '                            '    '开始读取流并设置编码方式
        '                            '    'new GZipStream(response.GetResponseStream(), CompressionMode.Decompress).CopyTo(_stream, 10240);
        '                            '    '.net4.0以下写法
        '                            '    _Stream = GetMemoryStream(New GZipStream(.GetResponseStream(), CompressionMode.Decompress))
        '                            'Else
        '                            '    '开始读取流并设置编码方式
        '                            '    'response.GetResponseStream().CopyTo(_stream, 10240);
        '                            '    '.net4.0以下写法
        '                            '    _Stream = GetMemoryStream(.GetResponseStream())
        '                            'End If

        '                            Dim RawResponse As Byte() = Me.m_MemoryStream.ToArray()
        '                            '从这里开始我们要无视编码了
        '                            '获取Byte
        '                            Dim temp As String = Encoding.[Default].GetString(RawResponse, 0, RawResponse.Length)
        '                            '<meta(.*?)charset([\s]?)=[^>](.*?)>
        '                            Dim meta As Match = Regex.Match(temp, "<meta([^<]*)charset=([^<]*)[""']", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
        '                            Dim charter As String = If((meta.Groups.Count > 2), meta.Groups(2).Value, String.Empty)
        '                            charter = charter.Replace("""", String.Empty).Replace("'", String.Empty).Replace(";", String.Empty)
        '                            If charter.Length > 0 Then
        '                                charter = charter.ToLower().Replace("iso-8859-1", "gbk")
        '                                Encoding = Encoding.GetEncoding(charter)
        '                            Else
        '                                If .CharacterSet.ToLower().Trim() = "iso-8859-1" Then
        '                                    Encoding = Encoding.GetEncoding("gbk")
        '                                Else
        '                                    If String.IsNullOrEmpty(.CharacterSet.Trim()) Then
        '                                        Encoding = Encoding.UTF8
        '                                    Else
        '                                        Encoding = Encoding.GetEncoding(.CharacterSet)
        '                                    End If
        '                                End If
        '                            End If

        '                            '得到返回的HTML
        '                            Me.m_HtmlCode = Encoding.GetString(RawResponse)
        '                        End With
        '                    ElseIf TypeOf m_WebResponse Is FileWebResponse Then
        '                        Me.m_HtmlCode = Encoding.GetString(Me.m_MemoryStream.ToArray())
        '                    ElseIf TypeOf m_WebResponse Is FtpWebResponse Then
        '                        Me.m_HtmlCode = Encoding.GetString(Me.m_MemoryStream.ToArray())
        '                    End If
        '                    ''==========================================================================================
        '                    Me.m_Title = StringHelper.GetHtmlDocTitle(Me.m_HtmlCode)

        '                    Me.OnCompleted(New AsyncCompletedEventArgs(Nothing, False, Me))
        '                End If
        '            Catch ex As Exception
        '                Me.OnCompleted(New AsyncCompletedEventArgs(ex, True, Me))
        '            End Try
        '        End Sub

        '        ''' <summary>
        '        ''' 异步获取网页源码
        '        ''' </summary>
        '        ''' <remarks></remarks>
        '        Public Overridable Sub GetHtmlCodeAnsyc()
        '            If Me.SiteUri Is Nothing Then
        '                Me.OnCompleted(New AsyncCompletedEventArgs(New Exception("网络地址不能为空"), True, Me))
        '                Exit Sub
        '            End If

        '            Try
        '                Me.m_WebRequest = HttpWebRequest.Create(Me.SiteUri)
        '                With Me.m_WebRequest
        '                    If TypeOf Me.m_WebRequest Is HttpWebRequest Then
        '                        With DirectCast(Me.m_WebRequest, HttpWebRequest)
        '                            .CookieContainer = Me.m_CookieContainer
        '                            .Referer = Me.SiteUrl
        '                            .Accept = Me.Accept
        '                            .UserAgent = Me.UserAgent
        '                        End With
        '                    ElseIf TypeOf Me.m_WebRequest Is FileWebRequest Then
        '                        With DirectCast(Me.m_WebRequest, FileWebRequest)
        '                            .ContentType = Me.ContentType
        '                        End With
        '                    ElseIf TypeOf Me.m_WebRequest Is FtpWebRequest Then
        '                        With DirectCast(Me.m_WebRequest, FileWebRequest)
        '                            .ContentType = Me.ContentType
        '                        End With
        '                    End If

        '                    .Method = Me.Method.ToString()
        '                End With

        '                Me.OnProgressChanged(New ProgressChangedEventArgs(CInt(Me.m_Increment), Me))
        '                Me.m_WebRequest.BeginGetResponse(New AsyncCallback(AddressOf RequestComplete), Me.m_WebRequest)
        '            Catch ex As Exception
        '                Me.OnCompleted(New AsyncCompletedEventArgs(ex, True, Me))
        '            End Try
        '        End Sub

#End Region


        ''' <summary>
        ''' 获取网页源码
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetHtmlCode() As WebDocumentInfo

            Dim _Stream As New MemoryStream()
            Dim _Result As WebDocumentInfo = New WebDocumentInfo()
            Try
                Dim _WebRequest As WebRequest = HttpWebRequest.Create(Me.SiteUri)
                Me.SetWebRequestProperties(_WebRequest)

                'With _WebRequest
                '    If TypeOf _WebRequest Is HttpWebRequest Then
                '        With DirectCast(_WebRequest, HttpWebRequest)
                '            .CookieContainer = Me.m_CookieContainer
                '            .ContentType = Me.ContentType
                '            .Referer = Me.SiteUrl
                '            .Accept = Me.Accept
                '            .UserAgent = Me.UserAgent
                '        End With
                '    ElseIf TypeOf _WebRequest Is FileWebRequest Then
                '        With DirectCast(_WebRequest, FileWebRequest)
                '            .ContentType = Me.ContentType
                '        End With
                '    ElseIf TypeOf _WebRequest Is FtpWebRequest Then
                '        With DirectCast(_WebRequest, FileWebRequest)
                '            .ContentType = Me.ContentType
                '        End With
                '    End If

                '    .Method = Me.Method.ToString()
                '    .ContentLength = _data.Length
                '    'If Not String.IsNullOrEmpty(Me.ProxyAddress) Then
                '    '.Proxy = New WebProxy("58.215.81.185", 1080)
                '    'End If
                'End With

                'If _data.Length > 0 Then
                '    _WebRequest.ContentLength = _data.Length
                '    _Stream = _WebRequest.GetRequestStream()
                '    _Stream.Write(_data, 0, _data.Length)
                '    _Stream.Close()
                '    _Stream.Dispose()
                'End If

                Dim _WebResponse As WebResponse = _WebRequest.GetResponse()
                If TypeOf _WebResponse Is HttpWebResponse Then

                    With DirectCast(_WebResponse, HttpWebResponse)
                        'GZIIP处理
                        If .ContentEncoding IsNot Nothing AndAlso .ContentEncoding.Equals("gzip", StringComparison.InvariantCultureIgnoreCase) Then
                            '开始读取流并设置编码方式
                            'new GZipStream(response.GetResponseStream(), CompressionMode.Decompress).CopyTo(_stream, 10240);
                            '.net4.0以下写法
                            _Stream = GetMemoryStream(New GZipStream(.GetResponseStream(), CompressionMode.Decompress))
                        Else
                            '开始读取流并设置编码方式
                            'response.GetResponseStream().CopyTo(_stream, 10240);
                            '.net4.0以下写法
                            _Stream = GetMemoryStream(.GetResponseStream())
                        End If

                        Dim RawResponse As Byte() = _Stream.ToArray()
                        '从这里开始我们要无视编码了
                        '获取Byte
                        Dim temp As String = Encoding.[Default].GetString(RawResponse, 0, RawResponse.Length)
                        '<meta(.*?)charset([\s]?)=[^>](.*?)>
                        Dim meta As Match = Regex.Match(temp, "<meta([^<]*)charset=([^<]*)[""']", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
                        Dim charter As String = If((meta.Groups.Count > 2), meta.Groups(2).Value, String.Empty)
                        charter = charter.Replace("""", String.Empty).Replace("'", String.Empty).Replace(";", String.Empty)
                        If charter.Length > 0 Then
                            charter = charter.ToLower().Replace("iso-8859-1", "gbk")
                            Encoding = Encoding.GetEncoding(charter)
                        Else
                            If .CharacterSet.ToLower().Trim() = "iso-8859-1" Then
                                Encoding = Encoding.GetEncoding("gbk")
                            Else
                                If String.IsNullOrEmpty(.CharacterSet.Trim()) Then
                                    Encoding = Encoding.UTF8
                                Else
                                    Encoding = Encoding.GetEncoding(.CharacterSet)
                                End If
                            End If
                        End If

                        '得到返回的HTML
                        _Result.HtmlCode = Encoding.GetString(RawResponse)
                    End With
                ElseIf TypeOf _WebResponse Is FileWebResponse Then
                    With DirectCast(_WebResponse, FileWebResponse)
                        _Stream = GetMemoryStream(.GetResponseStream())
                    End With
                ElseIf TypeOf _WebResponse Is FtpWebResponse Then
                    With DirectCast(_WebResponse, FtpWebResponse)
                        _Stream = GetMemoryStream(.GetResponseStream())
                    End With
                End If



                If String.IsNullOrEmpty(_Result.HtmlCode) AndAlso _Stream IsNot Nothing Then
                    _Stream.Position = 0    '设置流为起始位置
                    Using _StreamReader As New StreamReader(_Stream, Me.Encoding)
                        _Result.HtmlCode = _StreamReader.ReadToEnd()
                    End Using
                End If

                With _Result
                    .Title = StringHelper.GetHtmlDocTitle(.HtmlCode)
                    .Data = _Stream.ToArray()
                    .Encoder = Me.Encoding
                    .SiteUri = Me.SiteUri
                End With
            Catch ex As Exception
                Throw ex
            Finally
                If _Stream IsNot Nothing Then
                    _Stream.Close()
                    _Stream.Dispose()
                End If
            End Try

            Return _Result
        End Function

        ''' <summary>
        ''' 下载数据
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function DownloadData() As Byte()
            Dim _Result(0) As Byte
            Dim _Request As WebRequest = Nothing
            Dim _Response As WebResponse = Nothing
            Try
                ' Get a data stream from the url
                _Request = WebRequest.Create(Me.SiteUri)
                Me.SetWebRequestProperties(_Request)
                _Response = _Request.GetResponse()
                Using _MemoryStream As MemoryStream = GetMemoryStream(_Response.GetResponseStream())
                    _Result = _MemoryStream.ToArray()
                End Using
            Catch ex As Exception
                Throw ex
            Finally
                If _Request IsNot Nothing Then
                    _Request.Abort()
                    _Request = Nothing
                End If

                If _Response IsNot Nothing Then
                    _Response.Close()
                    _Response = Nothing
                End If
            End Try

            Return _Result
        End Function

        ''' <summary>
        ''' 下载文件
        ''' </summary>
        ''' <param name="savePath">文件保存路径</param>
        ''' <remarks></remarks>
        Public Sub DownloadFile(savePath As String)
            Dim _Data() As Byte = Me.DownloadData()
            Using fs As New FileStream(savePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)
                fs.Write(_Data, 0, _Data.Length)
            End Using
        End Sub


#End Region

#Region "IDisposable Support"
        Private disposedValue As Boolean ' 检测冗余的调用

        ' IDisposable
        Protected Overridable Sub Dispose(disposing As Boolean)
            If Not Me.disposedValue Then
                If disposing Then
                    ' TODO: 释放托管状态(托管对象)。


                    'If Me.m_MemoryStream IsNot Nothing Then
                    '    Me.m_MemoryStream.Flush() : Me.m_MemoryStream.Close() : Me.m_MemoryStream.Dispose()
                    '    Me.m_MemoryStream = Nothing
                    'End If

                    'If Me.m_WebResponse IsNot Nothing Then
                    '    Me.m_WebResponse.Close()
                    '    Me.m_WebResponse = Nothing
                    'End If

                    'If Me.m_WebRequest IsNot Nothing Then
                    '    Me.m_WebRequest.Abort()
                    '    Me.m_WebRequest = Nothing
                    'End If

                    Console.WriteLine("访问 {0} 结束，{1} 销毁 WebAssistant 类.", Me.SiteUrl, DateTime.Now())

                End If

                ' TODO: 释放非托管资源(非托管对象)并重写下面的 Finalize()。
                ' TODO: 将大型字段设置为 null。
            End If
            Me.disposedValue = True
        End Sub

        ' TODO: 仅当上面的 Dispose(ByVal disposing As Boolean)具有释放非托管资源的代码时重写 Finalize()。
        'Protected Overrides Sub Finalize()
        '    ' 不要更改此代码。请将清理代码放入上面的 Dispose(ByVal disposing As Boolean)中。
        '    Dispose(False)
        '    MyBase.Finalize()
        'End Sub

        ' Visual Basic 添加此代码是为了正确实现可处置模式。
        Public Sub Dispose() Implements IDisposable.Dispose
            ' 不要更改此代码。请将清理代码放入上面的 Dispose (disposing As Boolean)中。
            Dispose(True)
            GC.SuppressFinalize(Me)
        End Sub
#End Region


        ''' <summary>
        ''' 获取网页源码时，提交的方式
        ''' </summary>
        ''' <remarks></remarks>
        Public Enum MethodType
            [Get]
            [Post]
        End Enum


    End Class

End Namespace
